<?php
namespace App\Services\Spider;
use QL\QueryList;
use GuzzleHttp\Client;
 
class ChinasoDrive extends God
{
    protected function claws(string $keyword)
    {
        $keyword = '打工人';
        
        $html = $this->get_page($keyword);
        if ($html == false) return null;
    
        $ql = QueryList::html($html)->removeHead();
        $titles = $ql->find('h3.list-item');
dd($titles);




       

    }

    protected function get_page($keyword) {
      
        $headers = [                            
            'content-type' => 'text/html; charset=utf-8',  
            'Host'=>'m.chinaso.com',                  
            'referer' => 'm.chinaso.com',
            // 'User-Agent'=> 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
            'Cookie'=>'br-client=3fb22024-75b4-431d-b759-aa7afb1d3700; uid=CgqAiWUK96YAfBoXBdDUAg==; br-session-2753=502a4d8d-b8b0-430f-b9b0-ef66d65bee47|1695217575493|1695217575663|4; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218ab2d768d77d-05289843fc590e4-3e604809-3740678-18ab2d768d81ae%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThhYjJkNzY4ZDc3ZC0wNTI4OTg0M2ZjNTkwZTQtM2U2MDQ4MDktMzc0MDY3OC0xOGFiMmQ3NjhkODFhZSJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218ab2d768d77d-05289843fc590e4-3e604809-3740678-18ab2d768d81ae%22%7D'
        ];
    
  
        // $api = "http://www.chinaso.com/v5/general/v1/search/baike?q={$keyword}&ps=15&start_index=0&pn=1&force=&bid=1085925881652862";

        $api = "https://www.wuzhuiso.com/s?q=%E6%88%91%E4%BB%AC%E6%89%93%E5%B7%A5%E4%BA%BA&src=m_www&a=news";

        
        // dump($api);
        $response = $this->getResponses($api,$headers,false);
    
        return $response?$response:null;
         
    }

    public function Cookie() {
        // 'Cookie'=>'br-client=3fb22024-75b4-431d-b759-aa7afb1d3700; uid=CgqAiWUK96YAfBoXBdDUAg==; br-session-2753=502a4d8d-b8b0-430f-b9b0-ef66d65bee47|1695217575493|1695217575663|4; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218ab2d768d77d-05289843fc590e4-3e604809-3740678-18ab2d768d81ae%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThhYjJkNzY4ZDc3ZC0wNTI4OTg0M2ZjNTkwZTQtM2U2MDQ4MDktMzc0MDY3OC0xOGFiMmQ3NjhkODFhZSJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218ab2d768d77d-05289843fc590e4-3e604809-3740678-18ab2d768d81ae%22%7D'


    }

    protected function getResponses($url, $headers = [], $isPost = true)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);

        curl_setopt($curl, CURLOPT_TIMEOUT, 5);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_POST, $isPost);

        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        // curl_setopt($curl, CURLOPT_PROXY, IP::get());

        if ($response = curl_exec($curl)) {
            curl_close($curl);
            return $response;
        }
 
        if ($message = curl_error($curl)) {
            // throw new \Exception(" >>>>>>>>>>>> TouTiao error：$url => {$message}");
            log('TouTiao error：' . $url . ' => ' . $message);
            return null;
        }
        curl_close($curl);
        return $response;
    }
    

}